var role = require("../server/lib/role");
var notify = require("../server/lib/notify");
var UserCon = iClass.get("User");
var BlogCon = iClass.get("Blog");
midEvent.on("blog_comment_change", function(blog_id, visitor_id) {
	var blog = BlogCon.get(blog_id);
	var comments = blog.getComments(visitor_id || role.getUser()._id);
	Object.keys(notify.conns).forEach(function(some_one_id) {
		if (UserCon.get(some_one_id)) {
			notify.send(notify.conns[some_one_id], "blog_comment_change", comments);
		}
	});
});
midEvent.on("new_blog", function(blog_id, visitor_id) {
	var blog = BlogCon.get(blog_id);
	var blog_detail = blog.getDetail(visitor_id);
	Object.keys(notify.conns).forEach(function(some_one_id) {
		var user = UserCon.get(some_one_id);
		if (user) {
			//TODO:判断博文对此用户的开放性
			notify.send(notify.conns[some_one_id], "new_blog", blog_detail);
		}
	});
});